package cn.hiapi.shopkeeper.service.shopkeeper;

import cn.hiapi.basic.security.TokenGet;
import cn.hiapi.basic.token.Token;
import cn.hiapi.interfaces.DispatchContext;
import cn.hiapi.interfaces.basic.IBasicQueryCallback;
import cn.hiapi.shop.entity.shop.Shop;
import cn.hiapi.shopkeeper.service.user.HistoryRecordService;
import org.springframework.stereotype.Service;

/**
 * @author AdinZ
 * @date 2023/3/17 9:47
 */
@Service
public class BasicQueryCallbackService implements IBasicQueryCallback {
    private final DispatchContext dispatchContext;

    public BasicQueryCallbackService(DispatchContext dispatchContext) {
        this.dispatchContext = dispatchContext;
    }

    @Override
    public <T> void detailCallback(T t) {
        if (t instanceof Shop) {
            Token<Object> token = TokenGet.get();
            if (token == null) return;
            this.dispatchContext.getServiceOne(HistoryRecordService.class)
                    .addRecord(token.getFid(), ((Shop) t).getId());
        }
    }
}
